<?php
echo $javascript->link('http://maps.google.com/maps/api/js?sensor=false',true); 

$maps = '';
$points = '';
$contens = '';
$markers = '';
$events = '';
$infowindow = '';
foreach ($params as $m => $md) {

	foreach ($md['points'] as $p => $d) {
		$points .= "var point{$m}{$p} = new google.maps.LatLng({$d['lat']},{$d['lng']});\n";
		$contens .= "var content{$m}{$p} = '{$d['content']}';\n";
		$markers .= "var marker{$m}{$p} = new google.maps.Marker({
			  		      position: point{$m}{$p}, 
			  		      map: {$m}, 
			  		      title: content{$m}{$p}
			  		  });\n";
		$infowindow .= "var infowindow{$m}{$p} = new google.maps.InfoWindow({
				        content: content{$m}{$p}
				    });";
		$events .= "google.maps.event.addListener(marker{$m}{$p}, 'click', function() {
				      infowindow{$m}{$p}.open({$m},marker{$m}{$p});
				    });\n";
	}
	
	$maps .= "
		{$points}
		var myOptions{$m} = {
			zoom: {$md['zoom']},
			center: point{$m}0,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var {$m} = new google.maps.Map(document.getElementById('{$m}'), myOptions{$m});
		
		{$contens}		
  		{$markers}      
	    {$infowindow}
	    {$events}
	    
	";
}
echo $javascript->codeBlock("

	// wyswietlanie mapy
	function initialize() {	    
	  {$maps}  		  		  
	}
	
	$(document).ready(function() {
		initialize();
	});
	",$options = array('allowCache'=>true,'safe'=>true,'inline'=>true));
?>
